package com.ziyunying.weather.ui.screen.util

import java.time.format.DateTimeFormatter
import java.time.ZonedDateTime

object DateUtils {

    // 将 ISO 格式字符串转为 ZonedDateTime
    fun parseIsoDateTime(isoString: String): ZonedDateTime {
        return ZonedDateTime.parse(isoString)
    }

    // 格式化为 "周二，5月20日"
    fun formatToWeekDayAndDate(zonedDateTime: ZonedDateTime): String {
        val formatter = DateTimeFormatter.ofPattern("E，M月d日")
        return zonedDateTime.format(formatter)
    }

    // 组合方法：输入字符串直接返回格式化结果
    fun formatObsTime(isoString: String): String {
        return try {
            val zoned = parseIsoDateTime(isoString)
            formatToWeekDayAndDate(zoned)
        } catch (e: Exception) {
            "未知日期"
        }
    }
}
